package com.osfw.framework.utils;

import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import org.apache.shiro.crypto.hash.Md5Hash;

/**
 * PasswordUtil 类的描述
 */
public class PasswordUtil {

    /**
     * 生成随机盐
     */
    public static String randomSalt() {
        // 一个Byte占两个字节，此处生成的3字节，字符串长度为6
        SecureRandomNumberGenerator secureRandom = new SecureRandomNumberGenerator();
        return secureRandom.nextBytes(3).toHex();
    }

    public static String encryptPassword(String loginName, String password, String salt) {
        return new Md5Hash(StringUtils.join(loginName, password), salt, 3).toHex();
    }

    public static void main(String[] args) {
        String salt = randomSalt();
        System.out.println("salt：" + salt);
        System.out.println("encryptPassword：" + encryptPassword("admin", "123456", salt));
        /*String base64 = ImageUtil.convertToBase64("D://bg_boyun1.jpeg");
        System.out.println("data:image/png;base64," + base64);*/
    }

}
